<?php
/**
 * Date: 2017/12/31
 * Time: 14:25
 */

namespace app\common\library;

use think\Db;
use think\helper\Time;

class WorkTime
{

    public static function runtime($uid, $w_time, $p_time,$project_id)
    {
        list($data['m_time'], $em) = Time::month();
        $data['uid'] = $uid;
        $info = DB::name('user_work')->where($data)->find();

        Db::startTrans();
        try {
            if ($info) {
                DB::name('user_work')->where($data)->setInc('w_time', $w_time / 60);
                DB::name('user_work')->where($data)->setInc('p_time', $p_time / 60);
            } else {
                $data['p_time'] = $p_time/60;
                $data['w_time'] = $w_time/60;
                DB::name('user_work')->insert($data);
            }
            Db::name('project')->where('id',$project_id)->setInc('w_time', $w_time / 60);
            Db::commit();
            return true;
        } catch (\Exception $e) {
            Db::rollback();
            return false;
        }
    }

}